#pragma once
#include"d3d9.h"
#include"d3dx9.h"
#include"dinput.h"

#include"string"
#include"FrameWorkGlobal.h"
#include"TraceEvent.h"
using namespace std;
//LPDIRECT3DTEXTURE9 CreateTextture(char filename[],int color);
class DXManager
{
private:
	LPDIRECT3D9 m_pD3D;
	LPDIRECT3DDEVICE9 m_pD3DDevice;
	IDirect3DSurface9* m_pBackBuffer;
	LPDIRECTINPUT m_pD3DInput;
	HWND m_hWnd;
	HINSTANCE m_hInstance;
	D3DPRESENT_PARAMETERS m_pPresent;

	int m_pScreenWidth;
	int m_pScreenHeight;
	bool m_pIsFullScreen;
	D3DXMATRIX m_MatView,m_MatProj;
	D3DXVECTOR3	m_VecCameraPos,m_VecCameraLook;
	D3DFORMAT FindDepthStencilFormat( ULONG AdapterOrdinal, D3DDISPLAYMODE Mode, D3DDEVTYPE DevType );
public:
	LPDIRECTINPUTDEVICE m_pKeyboardDevice;
	LPD3DXSPRITE m_pSprite;
	bool Init();
	bool InitKeyboardDevice();
	void Destroy();
	DXManager(HWND hwnd,HINSTANCE hInstance,int _Width,int _Height,bool _IsFull);
	void BeginRender();
	void EndRender();
	void ClearScreen();
	void BeginSprite();
	void EndSprite();
	IDirect3DSurface9 *CreateSurfaceFromFile(std::string filename);
	LPDIRECT3DDEVICE9 GetD3DDDevice();
	LPD3DXSPRITE GetD3DXSprite();
	void ShowSurface(IDirect3DSurface9 *surface,const RECT *srcrect,const RECT *desRect);

	void CreateCamera(float nearClip,float farClip);
	void MoveCamera(D3DXVECTOR3 vec);
	void PointCamera(D3DXVECTOR3 vec);
	
	LPDIRECT3DVERTEXBUFFER9 createVertexBuffer(int size,DWORD FVF);
	LPDIRECT3DINDEXBUFFER9 createIndexBuffer(int size,DWORD FVF);
	~DXManager(void);
};
